package com.vtuzx.kingdee.xqc_api.web;

import com.vtuzx.core.VtuzxException;
import com.vtuzx.core.bean.dto.VtuzxMap;
import com.vtuzx.core.bean.dto.VtuzxToken;
import com.vtuzx.core.constant.IVtuzxConst;
import com.vtuzx.core.utils.VtuzxUtil;
import com.vtuzx.kingdee.xqc_api.service.IXqcProduceService;
import com.vtuzx.web.constant.ApiType;
import com.vtuzx.web.validator.VtuzxValidator;
import com.vtuzx.web.web.VtuzxApi;
import com.vtuzx.web.web.VtuzxControlParam;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 生产领料
 */
@RequestMapping("/${vtuzx.fast.api.path}/${vtuzx.fast.api.version}/prd_task")
@RestController
public class XqcPrdTaskController {

    /** 生产服务 */
    @Autowired
    private IXqcProduceService produceService;

    private Map<ObjectId,Long> lastRequestTimeMap = new ConcurrentHashMap<>();


    /**
     * 生产任务单生成用料清单
     */
    @PostMapping("/task_bill_to_material_list")
    @VtuzxApi
    public Object taskBillToMaterialList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.taskBillToMaterialList(userId, userName, param);
    }


    /**
     * 创建生产任务单和用料清单
     */
    @PostMapping("/create_prd_task_bill")
    @VtuzxApi
    public Object createPrdTaskBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        produceService.createPrdTaskBill(userId, userName, param);
        return null;
    }

    /**
     * 审核生产订单
     */
    @PostMapping("/audit_prd_task_bill")
    @VtuzxApi
    public Object auditPrdTaskBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        produceService.auditPrdTaskBill(userId, userName, param);
        return null;
    }

    /**
     * 批量审核生产订单
     */
    @PostMapping("/audit_prd_task_bill_list")
    @VtuzxApi
    public Object auditPrdTaskBillList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        produceService.auditPrdTaskBillList(userId, userName, param);
        return null;
    }

    /**
     * 校验车间收货是否全都入库
     */
    @PostMapping("/check_prd_col_in_stock")
    @VtuzxApi
    public Object checkPrdColIstock(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.checkPrdColIstock(userId, userName, param);
    }

    /**
     * 查询入库单有没有同品通批次入到不同仓库的
     */
    @PostMapping("/check_prd_task")
    @VtuzxApi
    public Object checkPrdTask(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.checkPrdTask(userId, userName, param);
    }

    /**
     * 获取生产任务列表（pda）
     */
    @PostMapping("/get_prd_task_list_pda")
    @VtuzxApi
    public Object getPrdTaskListPda(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        List<String> characterKeyList = VtuzxUtil.getObject(token, "characterKeyList");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getPrdTaskListPda(userId, userName, characterKeyList, param);
    }

    /**
     * 获取生产任务列表（web）
     */
    @PostMapping("/get_prd_task_list_web")
    @VtuzxApi
    public Object getPrdTaskListWeb(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getPrdTaskListWeb(userId, userName, param);
    }

    /**
     * 获取生产任务列表（webBN）
     */
    @PostMapping("/get_prd_task_list_web_bn")
    @VtuzxApi
    public Object getPrdTaskListWebBn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getPrdTaskListWebBn(userId, userName, param);
    }

    /**
     * 获取生产任务详细（pda/web）
     */
    @PostMapping("/get_prd_task_detail")
    @VtuzxApi
    public Object getPrdTaskDetail(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getPrdTaskDetail(userId, userName, param);
    }

    /**
     * 获取生产任务详细（pda/web）BN
     */
    @PostMapping("/get_prd_task_detail_bn")
    @VtuzxApi
    public Object getPrdTaskDetailBn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getPrdTaskDetailBn(userId, userName, param);
    }

    /**
     * 获取用料清单列表（pda）
     */
    @PostMapping("/get_material_bom_list_pda")
    @VtuzxApi
    public Object getMaterialBomListPda(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getMaterialBomListPda(userId, userName, param);
    }

    /**
     * 获取用料清单列表（web）
     */
    @PostMapping("/get_material_bom_list_web")
    @VtuzxApi
    public Object getMaterialBomListWeb(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getMaterialBomListWeb(userId, userName, param);
    }

    /**
     * 获取用料清单详细（pda/web）
     */
    @PostMapping("/get_material_bom_detail")
    @VtuzxApi
    public Object getMaterialBomDetail(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getMaterialBomDetail(userId, userName, param);
    }

    /**
     * 用料清单领料扫描箱子
     */
    @PostMapping("/get_material_bom_box")
    @VtuzxApi
    public Object getMaterialBomBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getMaterialBomBox(userId, userName, param);
    }


    /**
     * 用料清单领料扫描rfid
     */
    @PostMapping("/get_material_bom_rfid")
    @VtuzxApi
    public Object getMaterialBomRfid(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getMaterialBomRfid(userId, userName, param);
    }


    /**
     * 用料清单领料添加箱子
     */
    @PostMapping("/add_material_bom_box")
    @VtuzxApi
    public Object addMaterialBomBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.addMaterialBomBox(userId, userName, param);
    }


    /**
     * 创建（生产领料单）领料订单
     */
    @PostMapping("/create_material_bom_pick_bill")
    @VtuzxApi
    public Object createMaterialBomPickBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.createMaterialBomPickBill(userId, userName, param);

    }


    /**
     * 审核（生产领料单）领料订单
     */
    @PostMapping("/audit_material_bom_pick_bill")
    @VtuzxApi
    public Object auditMaterialBomPickBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        produceService.auditMaterialBomPickBill(userId, userName, param);
        return null;
    }

    /**
     * 获取用户临时（生产领料单）生产领料物料列表
     */
    @PostMapping("/get_user_material_bom_pick_material")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "stockNo", label = "仓库", notNull = true)
    } )
    public Object getUserMaterialBomPickMaterial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String stockNo = VtuzxUtil.getString(param, "stockNo");
        String billNo = VtuzxUtil.getString(param, "billNo");
        String taskBillNo = VtuzxUtil.getString(param,"taskBillNo");
        return produceService.getUserMaterialBomPickMaterial(_userId, stockNo, billNo,taskBillNo);
    }

    /**
     * 获取用户临时(生产领料单)生产领料物料箱号列表
     */
    @PostMapping("/get_user_material_bom_pick_material_box")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "_detailId", label = "detailId", notNull = true),
    } )
    public Object getUserMaterialBomPickMaterialBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String _detailId = VtuzxUtil.getString(param, "_detailId");
        return produceService.getUserMaterialBomPickMaterialBox(_userId, _detailId);
    }

    /**
     * 删除用户临时(生产领料单)生产领料物料
     */
    @PostMapping("/delete_user_material_bom_pick_material")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "id", label = "物料行id", notNull = true)
    } )
    public Object deleteUserMaterialBomPickMaterial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String id = VtuzxUtil.getString(param, "id");
        produceService.deleteUserMaterialBomPickMaterial(_userId, id);
        return null;
    }

    /**
     * 删除用户临时(生产领料单)生产领料物料箱号
     */
    @PostMapping("/delete_user_material_bom_pick_material_box")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "id", label = "id", notNull = true)
    } )
    public Object deleteUserMaterialBomPickMaterialBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String id = VtuzxUtil.getString(param, "id");
        produceService.deleteUserMaterialBomPickMaterialBox(_userId, id);
        return null;
    }

    /**
     * 获取（生产用料单）生产领料单
     */
    @PostMapping("/get_material_bom_pick_bill")
    @VtuzxApi
    public Object getMaterialBomPickBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        int pageIndex = VtuzxUtil.getInt(param, "pageIndex");
        int pageSize = VtuzxUtil.getInt(param, "pageSize");
        return produceService.getMaterialBomPickBill(_userId, param, pageIndex, pageSize);
    }

    /**
     * 获取（生产用料单）生产领料单BN
     */
    @PostMapping("/get_material_bom_pick_bill_bn")
    @VtuzxApi
    public Object getMaterialBomPickBillBn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        int pageIndex = VtuzxUtil.getInt(param, "pageIndex");
        int pageSize = VtuzxUtil.getInt(param, "pageSize");
        return produceService.getMaterialBomPickBillBn(_userId, param, pageIndex, pageSize);
    }

    /**
     * 获取（生产用料单）生产领料单分录列表
     */
    @PostMapping("/get_material_bom_pick_bill_detail")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "单号", notNull = true)
    } )
    public Object getMaterialBomPickBillDetail(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getMaterialBomPickBillDetail(_userId, billNo);
    }

    /**
     * 获取（生产用料单）生产领料单分录列表BN
     */
    @PostMapping("/get_material_bom_pick_bill_detail_bn")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "单号", notNull = true)
    } )
    public Object getMaterialBomPickBillDetailBn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getMaterialBomPickBillDetailBn(_userId, billNo);
    }

    /**
     * 获取（生产用料单）生产领料单分录的箱号详细
     */
    @PostMapping("/get_material_bom_pick_bill_box")
    @VtuzxApi
    public Object getMaterialBomPickBillDetailBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String _detailId = VtuzxUtil.getString(param, "_detailId");
        return produceService.getMaterialBomPickBillDetailBox(_userId, _detailId);
    }

    /**
     * 用料清单补料添加箱子
     */
    @PostMapping("/add_material_bom_supplement_box")
    @VtuzxApi
    public Object addMaterialBomSupplementBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.addMaterialBomSupplementBox(userId, userName, param);
    }

    /**
     * 创建（生产领料单）补料订单
     */
    @PostMapping("/create_material_bom_supplement_bill")
    @VtuzxApi
    public Object createMaterialBomSupplementBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.createMaterialBomSupplementBill(userId, userName, param);

    }

    /**
     * 审核（生产领料单）补料订单
     */
    @PostMapping("/audit_material_bom_supplement_bill")
    @VtuzxApi
    public Object auditMaterialBomSupplementBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        produceService.auditMaterialBomSupplementBill(userId, userName, param);
        return null;
    }


    /**
     * 获取用户临时（生产领料单）生产补料物料列表
     */
    @PostMapping("/get_user_material_bom_supplement_material")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "stockNo", label = "仓库", notNull = true)
    } )
    public Object getUserMaterialBomSupplementMaterial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String stockNo = VtuzxUtil.getString(param, "stockNo");
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getUserMaterialBomSupplementMaterial(_userId, stockNo, billNo);
    }

    /**
     * 获取用户临时(生产领料单)生产补料物料箱号列表
     */
    @PostMapping("/get_user_material_bom_supplement_material_box")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "_detailId", label = "detailId", notNull = true),
    } )
    public Object getUserMaterialBomSupplementMaterialBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String _detailId = VtuzxUtil.getString(param, "_detailId");
        return produceService.getUserMaterialBomSupplementMaterialBox(_userId, _detailId);
    }

    /**
     * 删除用户临时(生产领料单)生产补料物料
     */
    @PostMapping("/delete_user_material_bom_supplement_material")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "id", label = "物料行id", notNull = true)
    } )
    public Object deleteUserMaterialBomSupplementMaterial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String id = VtuzxUtil.getString(param, "id");
        produceService.deleteUserMaterialBomSupplementMaterial(_userId, id);
        return null;
    }

    /**
     * 删除用户临时(生产领料单)生产补料物料箱号
     */
    @PostMapping("/delete_user_material_bom_supplement_material_box")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "id", label = "id", notNull = true)
    } )
    public Object deleteUserMaterialBomSupplementMaterialBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String id = VtuzxUtil.getString(param, "id");
        produceService.deleteUserMaterialBomSupplementMaterialBox(_userId, id);
        return null;
    }

    /**
     * 获取（生产用料单）生产补料单
     */
    @PostMapping("/get_material_bom_supplement_bill")
    @VtuzxApi
    public Object getMaterialBomSupplementBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        int pageIndex = VtuzxUtil.getInt(param, "pageIndex");
        int pageSize = VtuzxUtil.getInt(param, "pageSize");
        return produceService.getMaterialBomSupplementBill(_userId, param, pageIndex, pageSize);
    }

    /**
     * 获取（生产用料单）生产补料单BN
     */
    @PostMapping("/get_material_bom_supplement_bill_bn")
    @VtuzxApi
    public Object getMaterialBomSupplementBillBn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        int pageIndex = VtuzxUtil.getInt(param, "pageIndex");
        int pageSize = VtuzxUtil.getInt(param, "pageSize");
        return produceService.getMaterialBomSupplementBillBn(_userId, param, pageIndex, pageSize);
    }

    /**
     * 获取（生产用料单）生产补料单分录列表
     */
    @PostMapping("/get_material_bom_supplement_bill_detail")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "单号", notNull = true)
    } )
    public Object getMaterialBomSupplementBillDetail(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getMaterialBomSupplementBillDetail(_userId, billNo);
    }

    /**
     * 获取（生产用料单）生产补料单分录列表BN
     */
    @PostMapping("/get_material_bom_supplement_bill_detail_bn")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "单号", notNull = true)
    } )
    public Object getMaterialBomSupplementBillDetailBn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getMaterialBomSupplementBillDetailBn(_userId, billNo);
    }

    /**
     * 获取（生产用料单）生产补料单分录的箱号详细
     */
    @PostMapping("/get_material_bom_supplement_bill_box")
    @VtuzxApi
    public Object getMaterialBomSupplementBillDetailBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String _detailId = VtuzxUtil.getString(param, "_detailId");
        return produceService.getMaterialBomSupplementBillDetailBox(_userId, _detailId);
    }

    /**
     * 生产退料取生产领料补料列表
     */
    @PostMapping("/get_produce_return_list")
    @VtuzxApi
    public Object getProduceReturnList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String taskBillNo = VtuzxUtil.getString(param, "taskBillNo");
        return produceService.getProduceReturnList(_userId, taskBillNo);
    }

    /**
     * 生产退料取生产领料补料（箱号）
     */
    @PostMapping("/get_produce_return_box")
    @VtuzxApi
    public Object getProduceReturnBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String taskBillNo = VtuzxUtil.getString(param, "billNo");
        String boxNo = VtuzxUtil.getString(param, "boxNo");
        return produceService.getProduceReturnBox(_userId, taskBillNo, boxNo);
    }

    /**
     * 生产退料取生产领料补料（rfid）
     */
    @PostMapping("/get_produce_return_rfid")
    @VtuzxApi
    public Object getProduceReturnRfid(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String taskBillNo = VtuzxUtil.getString(param, "billNo");
        List<String> rfidList = VtuzxUtil.getObject(param, "rfidList");
        return produceService.getProduceReturnRfid(_userId, taskBillNo, rfidList);
    }


    /**
     * 用料清单退料添加箱子
     */
    @PostMapping("/add_material_bom_box_return")
    @VtuzxApi
    public Object addMaterialBomBoxReturn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        List<Map<String, Object>> dataList = VtuzxUtil.getObject(param, "boxList");
        String taskBillNo = VtuzxUtil.getString(param, "taskBillNo");
        String materialBomBillNo = VtuzxUtil.getString(param, "materialBomBillNo");
        produceService.addMaterialBomBoxReturn(userId, userName, dataList, taskBillNo, materialBomBillNo);
        return null;
    }


    /**
     * 创建（生产领料单）退料订单
     */
    @PostMapping("/create_material_bom_return_bill")
    @VtuzxApi
    public Object createMaterialBomReturnBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException, InterruptedException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        produceService.createMaterialBomReturnBill(userId, userName, param);
        return null;
    }

    /**
     * 获取生产退料列表（pda）
     */
    @PostMapping("/get_prd_return_list_pda")
    @VtuzxApi
    public Object getPrdReturnListPda(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getPrdReturnListPda(userId, userName, billNo);
    }

    /**
     * 获取用户临时（生产领料单）生产退料物料列表
     */
    @PostMapping("/get_user_material_bom_return_material")
    @VtuzxApi
    public Object getUserMaterialBomReturnMaterial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        return produceService.getUserMaterialBomReturnMaterial(_userId);
    }

    /**
     * 获取用户临时(生产领料单)生产退料物料箱号列表
     */
    @PostMapping("/get_user_material_bom_return_material_box")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "_detailId", label = "detailId", notNull = true),
    } )
    public Object getUserMaterialBomReturnMaterialBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String _detailId = VtuzxUtil.getString(param, "_detailId");
        return produceService.getUserMaterialBomReturnMaterialBox(_userId, _detailId);
    }

    /**
     * 删除用户临时(生产领料单)生产退料物料
     */
    @PostMapping("/delete_user_material_bom_return_material")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "id", label = "物料行id", notNull = true)
    } )
    public Object deleteUserMaterialBomReturnMaterial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String id = VtuzxUtil.getString(param, "id");
        produceService.deleteUserMaterialBomReturnMaterial(_userId, id);
        return null;
    }

    /**
     * 删除用户临时(生产领料单)生产退料物料箱号
     */
    @PostMapping("/delete_user_material_bom_re turn_material_box")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "id", label = "id", notNull = true)
    } )
    public Object deleteUserMaterialBomReturnMaterialBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String id = VtuzxUtil.getString(param, "id");
        produceService.deleteUserMaterialBomReturnMaterialBox(_userId, id);
        return null;
    }

    /**
     * 获取（生产用料单）生产退料单
     */
    @PostMapping("/get_material_bom_return_bill")
    @VtuzxApi
    public Object getMaterialBomReturnBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        int pageIndex = VtuzxUtil.getInt(param, "pageIndex");
        int pageSize = VtuzxUtil.getInt(param, "pageSize");
        return produceService.getMaterialBomReturnBill(_userId, param, pageIndex, pageSize);
    }

    /**
     * 获取（生产用料单）生产退料单BN
     */
    @PostMapping("/get_material_bom_return_bill_bn")
    @VtuzxApi
    public Object getMaterialBomReturnBillBn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        int pageIndex = VtuzxUtil.getInt(param, "pageIndex");
        int pageSize = VtuzxUtil.getInt(param, "pageSize");
        return produceService.getMaterialBomReturnBillBn(_userId, param, pageIndex, pageSize);
    }

    /**
     * 获取（生产用料单）生产退料单分录列表
     */
    @PostMapping("/get_material_bom_return_bill_detail")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "单号", notNull = true)
    } )
    public Object getMaterialBomReturnBillDetail(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getMaterialBomReturnBillDetail(_userId, billNo);
    }

    /**
     * 获取（生产用料单）生产退料单分录列表BN
     */
    @PostMapping("/get_material_bom_return_bill_detail_bn")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "单号", notNull = true)
    } )
    public Object getMaterialBomReturnBillDetailBn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getMaterialBomReturnBillDetailBn(_userId, billNo);
    }

    /**
     * 获取（生产用料单）生产退料单分录的箱号详细
     */
    @PostMapping("/get_material_bom_return_bill_box")
    @VtuzxApi
    public Object getMaterialBomReturnBillDetailBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String _detailId = VtuzxUtil.getString(param, "_detailId");
        return produceService.getMaterialBomReturnBillDetailBox(_userId, _detailId);
    }

    /**
     * 完成生产任务单生成车间收货
     */
    @PostMapping("/save_prd_task_to_prd_col")
    @VtuzxApi
    public Object savePrdTaskToPrdCol(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        String supplierBatchNo = VtuzxUtil.getString(param, "supplierBatchNo");
        String userName = VtuzxUtil.getString(token, "name");
        String produceDate = VtuzxUtil.getString(param,"produceDate");
        produceService.savePrdTaskToPrdCol(_userId, userName, billNo, supplierBatchNo,produceDate);
        return null;
    }




    /**
     * 生产扫码入库的扫码(boxNo)
     */
    @PostMapping("/prd_in_scan_boxNo")
    @VtuzxApi
    public Object prdInScanBoxNo(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String userName = VtuzxUtil.getString(token, "name");
        String boxNo = VtuzxUtil.getString(param, "boxNo");
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.prdInScanBoxNo(_userId, userName, boxNo, billNo);

    }

    /**
     * 生产扫码入库的扫码(rfid)
     */
    @PostMapping("/prd_in_scan_rfid")
    @VtuzxApi
    public Object prdInScanRfid(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        String userName = VtuzxUtil.getString(token, "name");
        List<String> rfidList = VtuzxUtil.getObject(param, "rfidList");
        return produceService.prdInScanRfid(_userId, userName, billNo, rfidList);
    }

    /**
     * 生产扫码入库加箱子
     */
    @PostMapping("/add_prd_in_box_list")
    @VtuzxApi
    public Object addPrdInBoxList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String userName = VtuzxUtil.getString(token, "name");
        List<Map<String, Object>> boxList = VtuzxUtil.getObject(param, "boxList");
        String stockNo = VtuzxUtil.getString(param, "stockNo");
        String locationNo = VtuzxUtil.getString(param, "locationNo");
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.addPrdInBoxList(_userId, userName, boxList, stockNo, locationNo, billNo);
    }

    /**
     * 生产扫码入库创建订单
     */
    @PostMapping("/create_prd_in_bill")
    @VtuzxApi
    public Object createPrdInBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String userName = VtuzxUtil.getString(token, "name");
        String stockNo = VtuzxUtil.getString(param, "stockNo");
        String taskBillNo = VtuzxUtil.getString(param, "taskBillNo");
        //从map中查找上次请求的时间戳
        Long lastRequestTime = lastRequestTimeMap.get(_userId);
        //如果为空或者上次请求的时间戳与当前时间做差大于5s，则视为新请求，否则重复请求。
        //如果第一次请求没有完成，再次请求就会出现入库重复的情况
        if (lastRequestTime == null || System.currentTimeMillis() - lastRequestTime > 20000) {
            lastRequestTimeMap.put(_userId, System.currentTimeMillis());
            // 处理请求
            produceService.createPrdInBill(_userId, userName, taskBillNo, stockNo);
        } else {
            // 重复请求
            throw new VtuzxException("正在入库，请不要重复点击");
        }
        return null;
    }

    /**
     * 获取用户临时（生产领料单）生产入库物料列表
     */
    @PostMapping("/get_user_material_bom_in_material")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "stockNo", label = "仓库", notNull = true)
    } )
    public Object getUserMaterialBomInMaterial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String stockNo = VtuzxUtil.getString(param, "stockNo");
        return produceService.getUserMaterialBomInMaterial(_userId, stockNo);
    }

    /**
     * 获取用户临时(生产领料单)生产入库物料箱号列表
     */
    @PostMapping("/get_user_material_bom_in_material_box")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "id", label = "detailId", notNull = true),
    } )
    public Object getUserMaterialBomInMaterialBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String _detailId = VtuzxUtil.getString(param, "id");
        return produceService.getUserMaterialBomInMaterialBox(_userId, _detailId);
    }

    /**
     * 删除用户临时(生产领料单)生产入库物料
     */
    @PostMapping("/delete_user_material_bom_in_material")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "id", label = "物料行id", notNull = true)
    } )
    public Object deleteUserMaterialBomInMaterial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String id = VtuzxUtil.getString(param, "id");
        produceService.deleteUserMaterialBomInMaterial(_userId, id);
        return null;
    }

    /**
     * 删除用户临时(生产领料单)生产入库物料箱号
     */
    @PostMapping("/delete_user_material_bom_in_material_box")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "id", label = "id", notNull = true)
    } )
    public Object deleteUserMaterialBomInMaterialBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String id = VtuzxUtil.getString(param, "id");
        produceService.deleteUserMaterialBomInMaterialBox(_userId, id);
        return null;
    }



    /**
     * 获取生产任务的生产入库单
     */
    @PostMapping("/get_prd_in_list")
    @VtuzxApi
    public Object getPrdInList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        int pageIndex = VtuzxUtil.getInt(param, IVtuzxConst.Key_pageIndex);
        int pageSize = VtuzxUtil.getInt(param, IVtuzxConst.Key_pageSize, 10);
        return produceService.getPrdInList(_userId, pageIndex, pageSize, param);
    }

    /**
     * 获取生产任务的生产入库单分录列表
     */
    @PostMapping("/get_prd_in_detail")
    @VtuzxApi
    public Object getPrdInDetail(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getPrdInDetail(_userId, billNo);
    }

    /**
     * 获取生产任务的生产入库单分录的箱号详细
     */
    @PostMapping("/get_prd_in_detail_box")
    @VtuzxApi
    public Object getPrdInDetailBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String _detailId = VtuzxUtil.getString(param, "_detailId");
        return produceService.getPrdInDetailBox(_userId, _detailId);
    }

    /**
     * 获取pda生产任务列表（领料）
     */
    @PostMapping("/get_prd_task_list_pick")
    @VtuzxApi
    public Object getPrdTaskListPick(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getPrdTaskListPick(userId, userName, param);
    }

    /**
     * 获取pda生产任务列表（补、退）
     */
    @PostMapping("/get_prd_task_list_supplement_return")
    @VtuzxApi
    public Object getPrdTaskListSupplementReturn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getPrdTaskListSupplementReturn(userId, userName, param);
    }

    /**
     * 分选完成任务获取物料
     */
    @PostMapping("/get_sorting_save_task_material")
    @VtuzxApi
    public Object getSortingSaveTaskMaterial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getSortingSaveTaskMaterial(userId, userName, param);
    }

    /**
     * 任务单领料车间主任确认
     */
    @PostMapping("/material_bom_pick_confirm")
    @VtuzxApi
    public Object materialBomPickConfirm(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        produceService.materialBomPickConfirm(userId, userName, param);
        return null;
    }


    /**
     * 分选物料选择
     */
    @PostMapping("/get_bom_sorting_list")
    @VtuzxApi
    public Object getBomSortingList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getBomSortingList(userId, userName, param);

    }

    /**
     * 删除生产任务单、用料清单
     */
    @PostMapping("/delete_prd_task_bill")
    @VtuzxApi
    public Object deletePrdTaskBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        produceService.deletePrdTaskBill(_userId, billNo);
        return null;
    }

    /**
     * 关闭生产订单
     */
    @PostMapping("/close_prd_order")
    @VtuzxApi
    public Object closePrdOrder(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        List<String> billNoList = VtuzxUtil.getObject(param, "billNoList");
        produceService.closePrdOrder(_userId, billNoList);
        return null;
    }
//
//    /**
//     * 反盐入库添加箱子
//     */
//    @PostMapping("/add_desalting_in_stock_box")
//    @VtuzxApi
//    public Object addDesaltingInStockBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
//        String userName = VtuzxUtil.getString(token, "name");
//        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
//        return produceService.addDesaltingInStockBox(userId, userName, param);
//    }
    /**
     * 创建反盐收货
     */
    @PostMapping("/create_desalting_in_stock_bill")
    @VtuzxApi
    public Object createDesaltingInStockBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        produceService.createDesaltingInStockBill(userId, userName, param);
        return null;
    }

//    /**
//     * 获取用户临时反盐入库物料列表
//     */
//    @PostMapping("/get_user_desalting_in_stock_material")
//    @VtuzxApi( fields = {
//            @VtuzxValidator(key = "stockNo", label = "仓库", notNull = true)
//    } )
//    public Object getUserDesaltingInStockMaterial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
//        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
//        String stockNo = VtuzxUtil.getString(param, "stockNo");
//        return produceService.getUserDesaltingInStockMaterial(_userId, stockNo);
//    }
//
//    /**
//     * 获取用户临时反盐入库物料箱号列表
//     */
//    @PostMapping("/get_user_desalting_in_stock_material_box")
//    @VtuzxApi( fields = {
//            @VtuzxValidator(key = "_detailId", label = "detailId", notNull = true),
//    } )
//    public Object getUserDesaltingInStockMaterialBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
//        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
//        String _detailId = VtuzxUtil.getString(param, "_detailId");
//        return produceService.getUserDesaltingInStockMaterialBox(_userId, _detailId);
//    }
//
//    /**
//     * 删除用户临时反盐入库物料
//     */
//    @PostMapping("/delete_user_desalting_in_stock_material")
//    @VtuzxApi( fields = {
//            @VtuzxValidator(key = "id", label = "物料行id", notNull = true)
//    } )
//    public Object deleteUserDesaltingInStockMaterial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
//        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
//        String id = VtuzxUtil.getString(param, "id");
//        produceService.deleteUserDesaltingInStockMaterial(_userId, id);
//        return null;
//    }
//
//    /**
//     * 删除用户临时反盐入库物料箱号
//     */
//    @PostMapping("/delete_user_desalting_in_stock_material_box")
//    @VtuzxApi( fields = {
//            @VtuzxValidator(key = "id", label = "id", notNull = true)
//    } )
//    public Object deleteUserDesaltingInStockMaterialBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
//        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
//        String id = VtuzxUtil.getString(param, "id");
//        produceService.deleteUserDesaltingInStockMaterialBox(_userId, id);
//        return null;
//    }

    /**
     * 获取反盐入库单
     */
    @PostMapping("/get_desalting_in_stock_bill")
    @VtuzxApi
    public Object getDesaltingInStockBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        int pageIndex = VtuzxUtil.getInt(param, "pageIndex");
        int pageSize = VtuzxUtil.getInt(param, "pageSize");
        return produceService.getDesaltingInStockBill(_userId, param, pageIndex, pageSize);
    }

    /**
     * 获取反盐入库单分录列表
     */
    @PostMapping("/get_desalting_in_stock_bill_detail")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "单号", notNull = true)
    } )
    public Object getDesaltingInStockBillDetail(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getDesaltingInStockBillDetail(_userId, billNo);
    }

    /**
     * 获取反盐入库单分录的箱号详细
     */
    @PostMapping("/get_desalting_in_stock_bill_box")
    @VtuzxApi
    public Object getDesaltingInStockBillDetailBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String _detailId = VtuzxUtil.getString(param, "_detailId");
        return produceService.getDesaltingInStockBillDetailBox(_userId, _detailId);
    }

    /**
     * 生产任务扫码跳转(退料)
     */
    @PostMapping("/get_prd_task_bill_number_return")
    @VtuzxApi
    public Object getPrdTaskBillNumberReturn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getPrdTaskBillNumberReturn(_userId, billNo);
    }


    /**
     * 即时库存不正确数据查询
     */
    @PostMapping("/inventory_test")
    @VtuzxApi
    public Object inventoryTest(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String stockNo = VtuzxUtil.getString(param, "stockNo");
        return produceService.inventoryTest(_userId, stockNo);
    }


    /**
     * 生产任务完工
     */
    @PostMapping("/prd_task_end")
    @VtuzxApi
    public Object prdTaskEnd(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        String billNo = VtuzxUtil.getString(param, "billNo");
        produceService.prdTaskEnd(_userId, name, billNo);
        return null;
    }


//    /**
//     * 车间收货选择行领料单入库
//     */
//    @PostMapping("/prd_task_end")
//    @VtuzxApi
//    public Object prdTaskEnd(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
//        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
//        String billNo = VtuzxUtil.getString(param, "billNo");
//        produceService.prdTaskEnd(_userId, billNo);
//        return null;
//    }

    /**
     * 获取生产任务的退料入库单
     */
    @PostMapping("/get_return_in_list")
    @VtuzxApi
    public Object getReturnInList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        int pageIndex = VtuzxUtil.getInt(param, IVtuzxConst.Key_pageIndex);
        int pageSize = VtuzxUtil.getInt(param, IVtuzxConst.Key_pageSize, 10);
        return produceService.getReturnInList(_userId, pageIndex, pageSize, param);
    }

    /**
     * 获取生产任务的退料入库单分录列表
     */
    @PostMapping("/get_return_in_detail")
    @VtuzxApi
    public Object getReturnInDetail(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getReturnInDetail(_userId, billNo);
    }

    /**
     * 获取生产任务的生产退料单分录的箱号详细
     */
    @PostMapping("/get_return_in_detail_box")
    @VtuzxApi
    public Object getReturnInDetailBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String _detailId = VtuzxUtil.getString(param, "_detailId");
        return produceService.getReturnInDetailBox(_userId, _detailId);
    }

    /**
     * 完成任务保存临时收货
     */
    @PostMapping("/save_task_add_prd_col")
    @VtuzxApi
    public Object saveTaskAddPrdCol(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException, InterruptedException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        produceService.saveTaskAddPrdCol(_userId, name, param);
        return null;
    }

    /**
     * 完成任务删除临时收货
     */
    @PostMapping("/save_task_delete_prd_col")
    @VtuzxApi
    public Object saveTaskDeletePrdCol(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        produceService.saveTaskDeletePrdCol(_userId, name, param);
        return null;
    }

    /**
     * 完成任务获取临时收货列表
     */
    @PostMapping("/save_task_get_prd_col_list")
    @VtuzxApi
    public Object saveTaskGetPrdColList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return produceService.saveTaskGetPrdColList(_userId, name, param);
    }

    /**
     * 完成任务临时箱子增加追溯码
     */
    @PostMapping("/save_task_add_prd_col_traceBack")
    @VtuzxApi
    public Object saveTaskAddPrdColTraceBack(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        produceService.saveTaskAddPrdColTraceBack(_userId, name, param);
        return null;
    }


    /**
     * 完成任务临时箱子取消打印
     */
    @PostMapping("/save_task_no_print")
    @VtuzxApi
    public Object saveTaskNoPrint(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        produceService.saveTaskNoPrint(_userId, name, param);
        return null;
    }


    /**
     * 根据生产任务单号查询领料单
     */
    @PostMapping("/get_material_pick_bill_task")
    @VtuzxApi
    public Object getMaterialPickBillTask(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return produceService.getMaterialPickBillTask(_userId, name, param);
    }

    /**
     * 获取生产任务执行列表（web）
     */
    @PostMapping("/get_prd_task_impl_list")
    @VtuzxApi
    public Object getPrdTaskImplList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getPrdTaskImplList(userId, userName, param);
    }

    /**
     * 下载生产任务执行报表
     */
    @PostMapping("/download_prd_task_impl_list")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadPrdTaskImplList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        return produceService.downloadPrdTaskImplList(token, param);
    }



    /**
     * 返回成品入库
     */
    @PostMapping("/get_material_by_box")
    @VtuzxApi
    public Object getMaterialByBox(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return produceService.getMaterialByBox(_userId, name, param);
    }


    /**
     * 创建简单成品入库
     */
    @PostMapping("/create_simple_prd_in")
    @VtuzxApi
    public Object createSimplePrdIn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        //从map中查找上次请求的时间戳
        Long lastRequestTime = lastRequestTimeMap.get(_userId);
        //如果为空或者上次请求的时间戳与当前时间做差大于5s，则视为新请求，否则重复请求。
        //如果第一次请求没有完成，再次请求就会出现入库重复的情况
        if (lastRequestTime == null || System.currentTimeMillis() - lastRequestTime > 20000) {
            lastRequestTimeMap.put(_userId, System.currentTimeMillis());
            // 处理请求
            produceService.createSimplePrdIn(_userId, name, param);
        } else {
            // 重复请求
           throw new VtuzxException("正在入库，请不要重复点击");
        }
        return null;
    }

    /**
     * 生产任务审核（web）
     */
    @PostMapping("/get_prd_task_audit_list")
    @VtuzxApi
    public Object getPrdTaskAuditList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.getPrdTaskAuditList(userId, userName, param);
    }
    /**
     * 下载生产任务审核报表
     */
    @PostMapping("/download_prd_task_audit_list")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadPrdTaskAuditList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        return produceService.downloadPrdTaskAuditList(token, param);
    }

    /**
     * 获取（生产用料单）生产领料单分录列表
     */
    @PostMapping("/get_produce_task_audit_detail")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "单号", notNull = true)
    } )
    public Object getProduceTaskAuditDetail(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String billNo = VtuzxUtil.getString(param, "billNo");
        return produceService.getProduceTaskAuditDetail(_userId, billNo);
    }

    /**
     * 修改生产任务备注
     */
    @PostMapping("/save_pro_task_bill")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "任务编号", notNull = true)
    } )
    public Object savePrdColBill(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return produceService.saveProTaskBill(_userId, name, param);
    }

    /**
     * 修改生产领料单打印状态
     * @param token
     * @param param
     * @return
     * @throws VtuzxException
     */
    @PostMapping("/update_material_seal")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "单号", notNull = true)
    } )
    public Object updateMaterialSeal(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return produceService.updateMaterialSeal(_userId, name, param);
    }

    /**
//     * 创建特殊（生产领料单）领料订单
//     */
//    @PostMapping("/create_material_bom_pick_bill_special")
//    @VtuzxApi
//    public Object createMaterialBomPickBillSpecial(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
//        String userName = VtuzxUtil.getString(token, "name");
//        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
//        return produceService.createMaterialBomPickBillSpecial(userId, userName, param);
//
//    }

    /**
     * 修改生产补料单打印状态
     * @param token
     * @param param
     * @return
     * @throws VtuzxException
     */
    @PostMapping("/update_supplement_seal")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "单号", notNull = true)
    } )
    public Object updateSupplementSeal(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return produceService.updateSupplementSeal(_userId, name, param);
    }

    /**
     * 修改生产任务单打印状态
     * @param token
     * @param param
     * @return
     * @throws VtuzxException
     */
    @PostMapping("/update_prdTask_seal")
    @VtuzxApi( fields = {
            @VtuzxValidator(key = "billNo", label = "单号", notNull = true)
    } )
    public Object updatePrdTaskSeal(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return produceService.updatePrdTaskSeal(_userId, name, param);
    }

    /**
     * 追溯扫码
     */
    @PostMapping("/add_prd_col_and_get_prd_col")
    @VtuzxApi
    public Object addPrdColAndSavePrdCol(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException, InterruptedException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token, "name");
        return produceService.addPrdColAndGetPrdCol(_userId, name, param);

    }

    /** 手动上传金蝶*/
    @PostMapping("upload_kingdee_task")
    @VtuzxApi
    public Object uploadKingdeeTask(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        String name = VtuzxUtil.getString(token,"name");
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        produceService.uploadKingdeeTask(_userId,name, param);
        return null;
    }

    /** 手动上传金蝶BN*/
    @PostMapping("upload_kingdee_task_bn")
    @VtuzxApi
    public Object uploadKingdeeTaskBn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        String name = VtuzxUtil.getString(token,"name");
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        produceService.uploadKingdeeTaskBn(_userId,name, param);
        return null;
    }

    /**
     * 生产任务关闭改审核
     */
    @PostMapping("/update_prd_type")
    @VtuzxApi
    public Object updatePrdType(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token,"name");
        List<String> billNoList = VtuzxUtil.getObject(param, "billNoList");
        produceService.updatePrdType(_userId,name, billNoList);
        return null;
    }

    /**
     * 生产任务完工改开工
     */
    @PostMapping("/update_prd_businessStatus")
    @VtuzxApi
    public Object updatePrdBusinessStatus(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String name = VtuzxUtil.getString(token,"name");
        List<String> billNoList = VtuzxUtil.getObject(param, "billNoList");
        produceService.updatePrdBusinessStatus(_userId,name, billNoList);
        return null;
    }

    /**
     * 用料清单领料添加箱子实际重量
     */
    @PostMapping("/change_material_bom_actual")
    @VtuzxApi
    public Object changeMaterialBomActual(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.changeMaterialBomActual(userId, userName, param);
    }

    /**
     * 修改补料单实际领料重量
     */
    @PostMapping("/change_suppliment_bom_actual")
    @VtuzxApi
    public Object changeSupplimentBomActual(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws VtuzxException {
        String userName = VtuzxUtil.getString(token, "name");
        ObjectId userId = VtuzxUtil.getObject(token, IVtuzxConst.Key__targetId);
        return produceService.changeSupplimentBomActual(userId, userName, param);
    }

    /**
     * 获取收货单（边，董，潘）
     */
    @PostMapping("/get_userName")
    @VtuzxApi
    public Object getUserName(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) {
        ObjectId _userId = token.getObject(IVtuzxConst.Key__targetId);
        String userName = VtuzxUtil.getString(token,"name");
        return new VtuzxMap("userName",userName);
    }

    /**
     * 导出生产任务
     */
    @PostMapping("/download_prd_task_list")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadPrdTaskList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        return produceService.downloadPrdTaskList(token, param);
    }

    /**
     * 导出生产任务BN
     */
    @PostMapping("/download_prd_task_list_bn")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadPrdTaskListBn(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        return produceService.downloadPrdTaskListBn(token, param);
    }


    /**
     * 导出生产领料单
     */
    @PostMapping("/download_material_pick_list")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadMaterialPickList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        return produceService.downloadMaterialPickList(token, param);
    }

    /**
     * 导出生产补料
     */
    @PostMapping("/download_material_suppliment_list")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadMaterialSupplimentList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        return produceService.downloadMaterialSupplimentList(token, param);
    }

    /**
     * 导出领料入库单
     */
    @PostMapping("/download_prd_in_list")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadPrdInList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        return produceService.downloadPrdInList(token, param);
    }

    /**
     * 导出退料入库单
     */
    @PostMapping("/download_prd_in_return_list")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadPrdInReturnList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        return produceService.downloadPrdInReturnList(token, param);
    }

    /**
     * 导出变品退料入库单
     */
    @PostMapping("/download_prd_in_desalting_list")
    @VtuzxApi(type = ApiType.Download)
    public Object downloadPrdInDesaltingList(@VtuzxControlParam VtuzxToken token, @RequestBody Map<String, Object> param) throws Exception {
        return produceService.downloadPrdInDesaltingList(token, param);
    }
}
